﻿Imports DevComponents.DotNetBar
Imports BLL

Public Class DatTiecCuoiConTrol
    Public ds_monAn As New List(Of MonAn)
    Public ds_dichVu As New List(Of DichVu)

    Public Sub KiemTra()
        Dim flag As Integer = 0
        If txtDienThoai.Text Is Nothing Then
            flag = 1
        End If
        If txtTenCoDau.Text Is Nothing Then
            flag = 1
        End If
        If txtTenChuRe.Text Is Nothing Then
            flag = 1
        End If
        If flag = 1 Then
            MessageBoxEx.Show("Chưa nhập đủ thông tin", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If

        'kiem tra tien dat coc khong am
        If nuSoBanDuTru.Value < 0 Then
            MessageBoxEx.Show("Số Bàn Dự Trữ Không Hợp Lệ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
        If nuSoLuongBan.Value < 0 Then
            MessageBoxEx.Show("Số Bàn Không Hợp Lệ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
        If nuTienDatCoc.Value < 0 Then
            MessageBoxEx.Show("Số Tiền Không Hợp Lệ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If


    End Sub

    'Refresh lại control

    Public Sub LoadDuLieu()
        'Lay danh sach sanh bang sanhbus
        txtMaTiecCuoi.Text = Convert.ToString(MakeId())
        txtDienThoai.Text = ""
        txtTenChuRe.Text = ""
        txtTenCoDau.Text = ""
        dtiNgay.Value = Now.Date
        nuTienDatCoc.Value = 0
        nuSoLuongBan.Value = 0
        nuSoBanDuTru.Value = 0
        cbThoiGian.SelectedItem = Nothing
        cbSanh.DataSource = Nothing
        gridMonAn.ClearSelection()
        gridMonAn.DataSource = Nothing
        gridDichVu.ClearSelection()
        gridDichVu.DataSource = Nothing
    End Sub

    Public Sub LamLai()
        'Lay danh sach sanh bang sanhbus
        txtDienThoai.Text = ""
        txtTenChuRe.Text = ""
        txtTenCoDau.Text = ""
        dtiNgay.Value = Now.Date
        nuTienDatCoc.Value = 0
        nuSoLuongBan.Value = 0
        nuSoBanDuTru.Value = 0
        cbThoiGian.SelectedItem = Nothing
        cbSanh.DataSource = Nothing
        gridMonAn.ClearSelection()
        gridMonAn.DataSource = Nothing
        gridDichVu.ClearSelection()
        gridDichVu.DataSource = Nothing
    End Sub
    Private Function MakeId() As Integer
        Dim ds As New List(Of TiecCuoi)
        Dim tiecCuoiBLL As New TiecCuoi_BLL()
        ds = tiecCuoiBLL.Lay()
        Dim lc As Integer = 0
        For i As Integer = 0 To ds.Count - 1
            If lc <= ds.Item(i).ID Then
                lc = ds.Item(i).ID
            End If
        Next
        Return lc + 1
    End Function
    Private Sub DatTiecCuoiConTrol_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDuLieu()
    End Sub

    Private Sub btnThemMonAn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemMonAn.Click
        gridMonAn.ClearSelection()
        gridMonAn.DataSource = Nothing
        Dim frm As New ThemMonAn()
        frm.ShowDialog()
        For Each MonAn As MonAn In frm.ds_monAn
            ds_monAn.Add(MonAn)
        Next
        gridMonAn.DataSource = ds_monAn
    End Sub

    Private Sub btnThemDichVu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemDichVu.Click
        gridDichVu.ClearSelection()
        gridDichVu.DataSource = Nothing
        Dim frm As New ThemDichVu()
        frm.ShowDialog()
        For Each DichVu As DichVu In frm.ds_dichVu
            ds_dichVu.Add(DichVu)
        Next
        gridDichVu.DataSource = ds_dichVu
    End Sub

    Private Sub cbThoiGian_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbThoiGian.SelectedIndexChanged
        If Not cbThoiGian.SelectedItem Is Nothing Then
            Dim ngay As DateTime = dtiNgay.Value
            Dim ca As String = cbThoiGian.SelectedItem.ToString()
            Dim sanh As New TiecCuoi_BLL()
            Dim dssanh As IList
            dssanh = sanh.LaySanh(ngay, ca)
            cbSanh.DataSource = dssanh
            cbSanh.DisplayMember = "TenSanh"
            cbSanh.ValueMember = "ID"
        End If

    End Sub
End Class
